home *** CD-ROM | disk | FTP | other *** search
Wrap
/******************************************************************/ /* */ /* TurboCAD for Windows */ /* Copyright (c) 1993 - 1999 */ /* International Microcomputer Software, Inc. */ /* (IMSI) */ /* All rights reserved. */ /* */ /******************************************************************/ // SdiDialog.cpp : implementation file // #include "stdafx.h" #include "InsSmObj.h" #include "SdiDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //extern CSdiDialog CSDlg; const HRESULT hRes = S_OK; const IID LIBID_IMSIGXLib = {0x6A481400,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; const IID IID_PickResult = {0x6A481123,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; //const IID IID_Tool = {0x6A48112C,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; const IID IID_Graphics = {0x6A48110A, 0xE531, 0x11CF, {0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; const IID IID_View = {0x6A481110, 0xE531, 0x11CF, {0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; const IID IID_Window = {0x6A481124, 0xE531, 0x11CF, {0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF} }; const CLSID CLSID_Application = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; const CLSID CLSID_XGraphic = {0x6A481803,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; //const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; //const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; static const IID IID_IAppEvents = { 0x6A481301, 0xE531, 0x11CF, { 0xA1, 0x15, 0x0, 0xA0, 0x24, 0x15, 0x8D, 0xAF } }; ///////////////////////////////////////////////////////////////////////////// // CSdiDialog dialog long a = 0; BEGIN_MESSAGE_MAP(CSdiDialog, CDialog) //{{AFX_MSG_MAP(CSdiDialog) ON_BN_CLICKED(ID_CLOSE, OnClose) ON_BN_CLICKED(IDC_PROPERTIES, OnProperties) ON_WM_DESTROY() ON_WM_SYSCOMMAND() //}}AFX_MSG_MAP /// ON_LBN_DBLCLK(IDC_LIST1, onDoubleClick) END_MESSAGE_MAP() BEGIN_DISPATCH_MAP(CSdiDialog, CDialog) //{{AFX_DISPATCH_MAP(CTCEventsApp) DISP_FUNCTION(CSdiDialog, "MouseDown", MouseDown, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL) DISP_FUNCTION(CSdiDialog, "MouseUp", MouseUp, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL) DISP_FUNCTION(CSdiDialog, "MouseMove", MouseMove, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL) // DISP_FUNCTION(CSdiDialog, "Drop", Drop, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH) DISP_FUNCTION(CSdiDialog, "DrawingBeforeClose", DrawingBeforeClose, VT_EMPTY, VTS_DISPATCH VTS_PBOOL) //}}AFX_DISPATCH_MAP END_DISPATCH_MAP() BEGIN_INTERFACE_MAP(CSdiDialog, CDialog) INTERFACE_PART(CSdiDialog, IID_IAppEvents, Dispatch) END_INTERFACE_MAP() void CSdiDialog::MouseDown(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, short Button, long Shift, long X, long Y, IMSI_BOOL* pbCancel) { *pbCancel = FALSE; } void CSdiDialog::MouseUp(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, short Button, long Shift, long X, long Y, IMSI_BOOL* pbCancel) { COleVariant varItem = (0L); COleVariant varOptional(varMissing); IDrawing *pIDwgTrg = NULL; /// current drawing pIDwgTrg = (IDrawing*) WhichDrawing; pIDwgTrg->AddRef(); Graphics *pGrs = NULL; *pbCancel = FALSE; CPoint point; point.x = X; point.y = Y; try { if(m_pDragGraphic != 0) { hRes = pIDwgTrg->get_Graphics(&pGrs); // get current graphic collection CHECK_HRESULT(hRes) CViewWnd *pPreview = (CViewWnd *) (GetDlgItem(IDC_PREVIEW)); hRes = pGrs->AddGraphic(m_pDragGraphic, varOptional, varOptional); CHECK_HRESULT(hRes) hRes = m_pDragGraphic->Update(); CHECK_HRESULT(hRes) if(m_pView != NULL) { m_pView->Release(); } m_pView = (View*) WhichView; m_pView->AddRef(); EndDrag(point); hRes = m_pView->Refresh(); CHECK_HRESULT(hRes) m_FirstClick = FALSE; } } catch (...) { TRACE_EXCEPTION("CSdiDialog::MouseUp") } if(m_pDragGraphic != NULL) { m_pDragGraphic->Release(); m_pDragGraphic = NULL; } if (m_pView != NULL) { m_pView->Release(); m_pView = NULL; } if (pGrs != NULL) { pGrs->Release(); pGrs = NULL; } if(pIDwgTrg != NULL) { pIDwgTrg->Release(); pIDwgTrg = NULL; } } void CSdiDialog::MouseMove(LPDISPATCH WhichDrawing, LPDISPATCH WhichView, LPDISPATCH WhichWindow, long Shift, long X, long Y, IMSI_BOOL* pbCancel) { // long i; CPoint point; point.x = X; point.y = Y; *pbCancel = FALSE; View *pViewCur = NULL; COleVariant varItem = (1L); try { if (m_FirstClick == TRUE) { HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT)); if(m_pView != NULL) { //m_pView->Release(); RELEASE(m_pView); } m_pView = (View *)WhichView; m_pView->AddRef(); CViewWnd *pPreview = (CViewWnd *) (GetDlgItem(IDC_PREVIEW)); hRes = pPreview->m_pPreviewGraphic->Duplicate(&m_pDragGraphic); CHECK_HRESULT(hRes) m_pDragGraphic->Release(); m_pDragGraphic = NULL; hRes = pPreview->m_pPreviewGrs->Remove(&varItem, &m_pDragGraphic); CHECK_HRESULT(hRes) hRes = m_pDragGraphic->put_ID(0); CHECK_HRESULT(hRes) m_FirstClick = FALSE; ::SetCursor(hOC); BeginDrag(point); } else { if (m_pDragGraphic != NULL && !m_bDragging)/// aalb && (nFlags & MK_LBUTTON)) { if (!BeginDrag(point)) { m_pDragGraphic->Release(); m_pDragGraphic = NULL; } } else if (m_bDragging) { pViewCur = (View *)WhichView; pViewCur->AddRef(); if (pViewCur != m_pView) // if view is changed then restart drag { if(m_pView != NULL) { RELEASE(m_pView); } m_pView = (View *)WhichView;//pViewCur; m_pView->AddRef(); pViewCur->Release(); pViewCur = NULL; RestartDrag(point); } Drag(point); } } } catch (...) { TRACE_EXCEPTION("CSdiDialog::OnMouseMove") } } // Get the running instance of the TurboCAD local server object from the ROT. void CSdiDialog::DisconnectEvents() { //HRESULT hRes = S_OK; if (m_pIApplication == NULL || m_dwEventConnection == 0) return; try { HRESULT hRes = m_pIApplication->DisconnectEvents(m_dwEventConnection); CHECK_HRESULT(hRes) if (FAILED(hRes)) { //AfxMessageBox("Connection not broken.");//# Localizable string# AfxMessageBox(IDS_STRING106); return; } m_dwEventConnection = 0; } catch (...) { TRACE_EXCEPTION("CSdiDialog::DisconnectEvents") } if(m_pIApplication != NULL) { m_pIApplication->Release(); m_pIApplication = NULL; } } //------------------------ CSdiDialog::CSdiDialog(CInsSmObj* pTool, CWnd* pParent, /*=NULL*/RegenMethods *pRgs) : CDialog(CSdiDialog::IDD, pParent), m_dwEventConnection(0), m_dwEventMask(~0UL), m_pIApplication(NULL), m_ptMouseDown(CPoint(0, 0)), m_FirstClick(FALSE), m_bDragging(FALSE), m_pView(NULL), m_pDragGraphic(NULL) { //{{AFX_DATA_INIT(CSdiDialog) m_listbox = _T(""); //}}AFX_DATA_INIT m_pTool = pTool; m_pTool->AddRef(); m_pTool->m_bRunned = TRUE; m_pRegMets = pRgs; ADDREF(m_pRegMets); } void CSdiDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSdiDialog) DDX_LBString(pDX, IDC_LIST1, m_listbox); //}}AFX_DATA_MAP } ///////////////////////////////////////////////////////////////////////////// // CSdiDialog message handlers BOOL CSdiDialog::OnInitDialog() { CDialog::OnInitDialog(); m_list.SubclassDlgItem( IDC_LIST1 , this ); CToolList *pList = (CToolList *)GetDlgItem(IDC_LIST1); m_wndView.SubclassDlgItem(IDC_PREVIEW, this); CViewWnd *pView = (CViewWnd *)GetDlgItem(IDC_PREVIEW); COleVariant varItem; CString cstrDesc; CString cstrName; HRESULT hRes = S_OK; RegenMethod *pRegMet = NULL; BSTR bstrDescription = NULL; BSTR bstrName = NULL; ImsiRegenMethodType regenType; EnableAutomation(); long NumRegs = 0; try { hRes = m_pRegMets->get_Count(&NumRegs); CHECK_HRESULT(hRes) for(long i = 0;i < NumRegs; i++) { varItem = i; hRes = m_pRegMets->get_Item(&varItem,&pRegMet); CHECK_HRESULT(hRes) hRes = pRegMet->get_Type(®enType); CHECK_HRESULT(hRes) // hRes = pRegMet->get_Description(&bstrDescription); // if (SUCCEEDED(hRes)) if(regenType == imsiAutomation) { hRes = pRegMet->get_Description(&bstrDescription); if (SUCCEEDED(hRes)) { cstrDesc = bstrDescription; ::SysFreeString(bstrDescription); bstrDescription = NULL; // if(cstrDesc != "HatchWizard.HatchWizard.1" || cstrDesc != "Smart.Connection.1") // if(cstrDesc != "HatchWizard.HatchWizard.1" || cstrDesc != "Smart.Connection.1" ) // { hRes = pRegMet->get_Name(&bstrName); CHECK_HRESULT(hRes) cstrName = bstrName; ::SysFreeString(bstrName); bstrName = NULL; if(cstrName == "Foundation.House" || cstrName == "AutoDim.House" || cstrName == "Schedule.Block") { } else { pList->AddString(cstrName); } // } } } } if(pList->SetCurSel(0) != LB_ERR) { pList->GetText(0 ,(pList->m_cstrCurSelected)); pView->CreatePreview(); pView->DoPreview(); ConnectEvents(); } } catch (...) { TRACE_EXCEPTION("CSdiDialog::OnInitDialog") } if (pRegMet != NULL) { pRegMet->Release(); pRegMet = NULL; } if (bstrDescription != NULL) ::SysFreeString(bstrDescription); if (bstrName != NULL) ::SysFreeString(bstrName); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CSdiDialog::PostNcDestroy() { CDialog::PostNcDestroy(); RELEASE(m_pRegMets) delete this; } void CSdiDialog::OnClose() { // TODO: Add your message handler code here and/or call default if(m_dwEventConnection != 0) DisconnectEvents(); m_pTool->m_bRunned = FALSE; if(m_pTool != NULL) { m_pTool->Release (); m_pTool = NULL; } if(m_pRegMets != NULL) { m_pRegMets->Release(); m_pRegMets = NULL; } CViewWnd *pView = (CViewWnd *)GetDlgItem(IDC_PREVIEW); pView->ClearAll(); CDialog::OnClose(); DestroyWindow(); } void CSdiDialog::ConnectEvents() { HRESULT hRes = S_OK; if (m_dwEventConnection != 0) { //AfxMessageBox("Already connected.");//# Localizable string# AfxMessageBox(IDS_STRING107); return; } m_pIApplication = NULL; try { hRes = m_pRegMets->get_Application(&m_pIApplication); CHECK_HRESULT(hRes) if (m_pIApplication == NULL) { //AfxMessageBox("Can't get a TurboCAD application!");//# Localizable string# AfxMessageBox(IDS_STRING108); return; } IDispatch* pUnkEventSink = GetIDispatch(TRUE); UpdateData(TRUE); COleVariant var((long)m_dwEventMask); hRes = m_pIApplication->ConnectEvents(pUnkEventSink, &var, (long*)&m_dwEventConnection); CHECK_HRESULT(hRes) if (FAILED(hRes)) { //AfxMessageBox("Connection not established.");//# Localizable string# AfxMessageBox(IDS_STRING109); return; } } catch (...) { TRACE_EXCEPTION("CSdiDialog::ConnectEvents") } } void CSdiDialog::OnProperties() { // TODO: Add your control notification handler code here VARIANT varIndex; varIndex.vt = VT_I4; varIndex.lVal = 0; Graphics* pGrs = NULL; CViewWnd *pView = (CViewWnd *) (GetDlgItem(IDC_PREVIEW)); RegenMethod * pCurRegenMethod = NULL; short i = 0; try { hRes = pView->m_pPreviewGraphic->get_Graphics(&pGrs); CHECK_HRESULT(hRes) hRes = pView->m_pPreviewGraphic->get_RegenType(&pCurRegenMethod); CHECK_HRESULT(hRes) hRes = pCurRegenMethod->RunPropertyPage(pGrs, &varIndex, &i ); CHECK_HRESULT(hRes) hRes = pView->m_pPreviewView->ZoomToExtents(); CHECK_HRESULT(hRes) pView->Invalidate(); } catch (...) { TRACE_EXCEPTION("CSdiDialog::OnProperties") } if (pCurRegenMethod != NULL) { pCurRegenMethod->Release(); pCurRegenMethod = NULL; } if(pGrs != NULL) { pGrs->Release(); pGrs = NULL; } } void CSdiDialog::OnSysCommand(UINT nID, LPARAM lParam ) { if (nID == SC_CLOSE) { if(m_dwEventConnection != 0) DisconnectEvents(); m_pTool->m_bRunned = FALSE; if(m_pTool != NULL) { m_pTool->Release (); m_pTool = NULL; } if(m_pRegMets != NULL) { m_pRegMets->Release(); m_pRegMets = NULL; } CViewWnd *pView = (CViewWnd *)GetDlgItem(IDC_PREVIEW); pView->ClearAll(); } CDialog::OnSysCommand(nID, lParam ); } ///------------------------------------------ // DragOutline functions BOOL CSdiDialog::BeginDrag(const CPoint& point) { VariantClear(&m_dragOutline); SAFEARRAYBOUND bound; bound.cElements = 0; bound.lLbound = 0; m_dragOutline.vt = VT_ARRAY|VT_R8; m_dragOutline.parray = ::SafeArrayCreate(VT_R8, 1, &bound); BoundingBox* Box = NULL; IVertex* vMax = NULL; IVertex* vMin = NULL; double x, y, x1, y1; x = x1 = y = y1 = 0; try { HRESULT hRes = m_pDragGraphic->CreateDragOutline(&m_dragOutline); CHECK_HRESULT(hRes) m_bDragging = TRUE; m_pDragGraphic->put_Visible(FALSE); VARIANT varState; varState.vt = VT_I4; varState.lVal = imsiDragBegin; hRes = m_pDragGraphic->CalcBoundingBox(NULL, &Box); CHECK_HRESULT(hRes) hRes = Box->get_Max(&vMax); CHECK_HRESULT(hRes) hRes = Box->get_Min(&vMin); CHECK_HRESULT(hRes) hRes = vMax->get_X(&x); CHECK_HRESULT(hRes) hRes = vMax->get_Y(&y); CHECK_HRESULT(hRes) hRes = vMin->get_X(&x1); CHECK_HRESULT(hRes) hRes = vMin->get_Y(&y1); CHECK_HRESULT(hRes) x = x1 + (x - x1)/2; y = y1 + (y - y1)/2; hRes = m_pView->ViewToScreen(x, y, &x1, &y1, NULL); CHECK_HRESULT(hRes) hRes = m_pView->DragOutline(&m_dragOutline, x1, y1, &varState); CHECK_HRESULT(hRes) varState.lVal = imsiDragContinue; hRes = m_pView->DragOutline(&m_dragOutline, point.x, point.y, &varState); CHECK_HRESULT(hRes) } catch (...) { TRACE_EXCEPTION("CSdiDialog::BeginDrag") } if (vMin != NULL) { vMin->Release(); vMin = NULL; } if (vMax != NULL) { vMax->Release(); vMax = NULL; } if (Box != NULL) { Box->Release(); Box = NULL; } return TRUE; } void CSdiDialog::Drag(const CPoint& point) { if (m_pView == NULL) return; VARIANT varState; varState.vt = VT_I4; varState.lVal = imsiDragContinue; try { HRESULT hRes = m_pView->DragOutline(&m_dragOutline, point.x, point.y, &varState); CHECK_HRESULT(hRes) } catch (...) { TRACE_EXCEPTION("CSdiDialog::Drag") } } void CSdiDialog::EndDrag(const CPoint& point) { m_bDragging = FALSE; if (m_pView == NULL || m_pDragGraphic == NULL) return; VARIANT varState; varState.vt = VT_I4; varState.lVal = imsiDragEnd; IMatrix *pMat = NULL; try { HRESULT hRes = m_pView->DragOutline(&m_dragOutline, point.x, point.y, &varState); CHECK_HRESULT(hRes) VariantClear(&m_dragOutline); double dx, dy, dz; dx = dy = dz = 0; double dxWorld, dyWorld, dzWorld; dxWorld = dyWorld = dzWorld = 0; hRes = m_pView->ScreenToView(point.x, point.y, &dx, &dy); CHECK_HRESULT(hRes) VARIANT var; var.vt = VT_ERROR; var.scode = DISP_E_PARAMNOTFOUND; ImsiSpaceModeType curMode; hRes = m_pView->get_SpaceMode(&curMode); CHECK_HRESULT(hRes) dxWorld = dx; dyWorld = dy; if(curMode == imsiModelSpace) { hRes = m_pView->ViewToWorld(dx, dy, dz, &dxWorld, &dyWorld, &dzWorld); CHECK_HRESULT(hRes) } hRes = m_pDragGraphic->MoveAbsolute(dxWorld, dyWorld, 0, &var, &var, &var, &pMat); CHECK_HRESULT(hRes) m_pDragGraphic->put_Visible(TRUE); } catch (...) { TRACE_EXCEPTION("CSdiDialog::EndDrag") } if(pMat != NULL) { pMat->Release(); pMat = NULL; } if (m_pDragGraphic != NULL) { m_pDragGraphic->Release(); m_pDragGraphic = NULL; } } void CSdiDialog::RestartDrag(const CPoint& point) { try { m_bDragging = FALSE; VARIANT varState; varState.vt = VT_I4; varState.lVal = imsiDragEnd; HRESULT hRes = m_pView->DragOutline(&m_dragOutline, point.x, point.y, &varState); CHECK_HRESULT(hRes) VariantClear(&m_dragOutline); BeginDrag(point); } catch (...) { TRACE_EXCEPTION("CSdiDialog::RestartDrag") } } void CSdiDialog::DrawingBeforeClose(LPDISPATCH WhichDrawing, BOOL FAR* Cancel) { *Cancel = FALSE; Drawings *pDrs = NULL; long n = 0; try { HRESULT hRes = m_pIApplication->get_Drawings(&pDrs); CHECK_HRESULT(hRes) hRes = pDrs->get_Count(&n); CHECK_HRESULT(hRes) if (n == 2) { if(m_dwEventConnection != 0) DisconnectEvents(); m_pTool->m_bRunned = FALSE; CViewWnd *pView = (CViewWnd *)GetDlgItem(IDC_PREVIEW); pView->ClearAll(); CSdiDialog::OnClose(); } } catch (...) { TRACE_EXCEPTION("CSdiDialog::DrawingBeforeClose") } if (pDrs != NULL) { pDrs->Release(); pDrs = NULL; } }